package net.obxlabs.tweetpad;

import net.silentlycrashing.util.*;
import java.util.List;
import twitter4j.*;

public class TwitterMessenger extends TwitterAdapter {
	private AsyncTwitter twitter;
	private RegisteredAction callbackAction;
	private RegisteredAction exceptionAction;
	
	public TwitterMessenger(RegisteredAction exceptionAction) {
		this.exceptionAction = exceptionAction;
	}
	
	public void setCredentials(String username, String password) {
		twitter = new AsyncTwitter(username, password);
	}
	
	public void getUserDetail(String username, RegisteredAction callbackAction) {
		this.callbackAction = callbackAction;
		twitter.getUserDetailAsync(username, this);
	}
	
	public void gotUserDetail(UserWithStatus userWithStatus) {
		if (callbackAction != null)
			callbackAction.invoke(new Object[] { userWithStatus });
	}
	
	public void getUserTimeline(RegisteredAction callbackAction) {
		this.callbackAction = callbackAction;
		twitter.getUserTimelineAsync(this);
	}
	
	public void getUserTimeline(String username, RegisteredAction callbackAction) {
		this.callbackAction = callbackAction;
		twitter.getUserTimelineAsync(username, this);
	}
	
	public void gotUserTimeline(List<Status> statuses) {
		if (callbackAction != null)
			callbackAction.invoke(new Object[] { statuses });
	}
	
	public void onException(TwitterException ex, int method) {
		if (exceptionAction != null)
			exceptionAction.invoke(new Object[] { ex, method });
    }
    
	
	/*
	Unimplemented methods
	
	public void gotFriendsTimeline(List<Status> statuses) {}
	public void gotPublicTimeline(List<Status> statuses) {}
	public void gotShow(Status status) {}
    public void updated(Status status) {}
    public void gotReplies(List<Status> statuses) {}
    public void gotFriends(List<User> users) {}
    public void gotFollowers(List<User> users) {}
    public void gotFeatured(List<User> users) {}
    public void gotUserDetail(UserWithStatus userWithStatus) {}
    public void gotDirectMessages(List<DirectMessage> messages) {}
    public void gotSentDirectMessages(List<DirectMessage> messages) {}
    public void sentDirectMessage(DirectMessage message) {}
    public void deletedDirectMessage(DirectMessage message) {}
    public void created(User user) {}
    public void destroyed(User user) {}
    public void onException(TwitterException te,int method) {}
    */
}
